#pragma once
#ifndef SET_H
#define SET_H

#include "headers.h"

struct RWI //rule with index
{
    /** fields **/
    const Rule* rule;
    int index;

    /** methods **/
    RWI(const Rule* ruleParam, int indexParam)
    {
        rule=ruleParam;
        index=indexParam;
    }
    QString getCurRHS() const
    {
        if(index<rule->RHS.length())
            return rule->RHS[index];
        return NULL;
    }
    QString getNextRHS() const
    {
        if(index+1<rule->RHS.length())
            return rule->RHS[index+1];
        return NULL;
    }
    bool finished() const
    {
        return index>=rule->RHS.length();
    }
    QString toString()
    {
        QString result = rule->LHS+" -> ";
        for(int i=0; i<rule->RHS.length(); i++)
        {
            if(index==i)
                result.append(".");
            result.append(rule->RHS[i]+" ");
        }
        if(index==rule->RHS.length())
            result.append(".");
        return result;
    }
    bool operator==(RWI rwi)
    {
        if(this->rule==rwi.rule)
            if(this->index==rwi.index)
                return true;
        return false;
    }
};

class Set
{
    friend class ParserGenerator;
public:
    /** methods **/
    Set(const Set*, QString);
    bool addRWI(const Rule*, int);
    bool isEmpty();
    QStringList toStringList();
    bool operator==(Set);
    /** ******* **/

private:
    /** fields **/
    //static set count to get number of new set
    static int SetCount;
    //number of current set
    int number;
    //list of rules with index
    QList<RWI> rules;
    //pointer to parent set that generates current set (just for info)
    QSet<const Set*> genSet;
    //symbol that generates current set (just for info)
    QString genSymbol;
    /** ****** **/
};

#endif // SET_H
